import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
// import get from '@dfeidao/atom-web/local/get';
// import set_node_cls from '@feidao/web/atom/browser/ui/set-node-cls';
import remove from '@dfeidao/atom-web/local/remove';
// import set from '@dfeidao/atom-web/local/set';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import s_get from '@dfeidao/atom-web/storage/get';

import render from '@dfeidao/atom-web/render/render';
import set_node_cls from '@dfeidao/atom-web/ui/set-node-cls';
// import show_loading from '../../atom-web/show-loading';
// import hide_loading from '../../atom-web/hide-loading';
import p001 from './p001';
import p002 from './p002';
// 查询
export default async function a001(fd: IFeidaoAiBrowserComponent) {
	// show_loading();
	// const prid = get(fd, 'productid');
	const prid = await s_get('productid');

	const name_inp = fd.data.node.querySelector<HTMLInputElement>('#name1').value;

	const query = {
		filter: {
			role_type_name: { $like: `%${name_inp}%` },
			productid: prid
		}
	};
	if (!name_inp) {
		delete query.filter.role_type_name;
	}

	const res = await nodejs<{ dataArray: object[] }>('role-type/zj-000001/s001', query);
	// hide_loading();
	render(fd, res.dataArray, p001, 'p001', 'inner');
	const p002_node = fd.data.node.querySelector<HTMLElement>('[data-feidao-presentation="p002"]');

	if (res.dataArray.length === 0) {
		render(fd, res.dataArray, p002, 'p002', 'inner');
		set_node_cls(p002_node, 'display-n', false);
	} else {
		const tb = res.dataArray;
		const data = tb.map((v) => {
			return { ...v, v: JSON.stringify(v) };
		});
		render(fd, data, p001, 'p001', 'inner');
		set_node_cls(p002_node, 'display-n', true);
	}
	remove(fd, '_id');

}
